import java.util.Arrays;

public class Solution {//https://leetcode.cn/problems/remove-element/description/
    public int removeElement(int[] nums, int val) {
        if (nums == null) {
            return -1;
        }
        int k = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                nums[k] = nums[i];
                k++;
            }
        }
        return k;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {3,2,2,3};
        int val = 2;
        int k = solution.removeElement(nums, val);
        System.out.println("新数组长度: " + k);
        System.out.println("处理后的数组: " + Arrays.toString(Arrays.copyOf(nums, k)));//这个相当于就是去nums的前面两项，得通过调试看
    }
}
